package cube.net.frame;

/**
 * 帧选择器，根据帧类型对帧进行选择
 * 
 * @author abiao
 */
public class FrameSelector {

    /**
     * 链头帧
     */
    private IdentityFrame head;

    /**
     * 初始化帧链
     */
    public void initChain(IdentityFrame... frames) {
        if (frames != null && frames.length > 0) {
            head = frames[0];
            for (int i = 0; i < frames.length - 1; i++) {
                frames[i].setNext(frames[i + 1]);
            }
        }
    }

    /**
     * 按标识选择帧
     */
    public IdentityFrame select(Identity identity) {
        return head == null ? null : head.get(identity).clone();
    }
}
